/* eslint-disable no-param-reassign */
import { createSelector, createSlice, PayloadAction } from '@reduxjs/toolkit';
import { ReduxState } from '..';
import { TimerModel } from '@/pages/schedule/type';

export type ScheduleStateList = {
  timerList: TimerModel[];
};

/**
 * Slice
 */
const scheduleStateSlice = createSlice({
  name: 'uiState',
  initialState: {
    timerList: [], // 初始化 timerList 为一个空数组，或者根据需要设置默认值
  } as ScheduleStateList,
  reducers: {
    updateTimerList(state, action: PayloadAction<ScheduleStateList['timerList']>) {
      state.timerList = action.payload;
    },
  },
});

/**
 * Actions
 */
export const { updateTimerList } = scheduleStateSlice.actions;

/**
 * Selectors
 */
// export const selectColorIndex = (state: ReduxState) => state.uiState.colorIndex;
// export const selectActiveIndex = createSelector(
//   [
//     (state: ReduxState) => state.uiState.whiteIndex,
//     (state: ReduxState) => state.uiState.colorIndex,
//     (_, isColor: boolean) => isColor,
//   ],
//   (whiteIndex, colorIndex, isColor) => {
//     return isColor ? colorIndex : whiteIndex;
//   }
// );

export const selectTimerList = (state: ReduxState) => state.scheduleState.timerList;
/**
 * Reducer
 */
export default scheduleStateSlice.reducer;
